<template>
    <div class="my-container">
        <!-- 用户头部区域 -->
      <div class="header">
        <!-- 登录显示的头部区域 -->
        <div class="header login" v-if="showLogin">
           <div class="base">
              <div class="left">
                <van-image fit="cover" :src="userinfo.photo ||  'https://img.yzcdn.cn/vant/cat.jpeg'" class="avatar mobile-img" round />
                <span class="name">{{ userinfo.name || "黑马头条"}}</span>
              </div>
              <div class="right">
                <van-button type="default" size="mini" round>编辑资料</van-button>
              </div>
            </div>
            <div class="data">
              <div class="data-item">
                <span>{{userinfo.art_count}}</span>
                <span>头条</span>
              </div>
              <div class="data-item">
                <span>{{userinfo.fans_count}}</span>
                <span>关注</span>
              </div>
              <div class="data-item">
                <span>{{userinfo.follow_count}}</span>
                <span>粉丝</span>
              </div>
              <div class="data-item">
                <span>{{userinfo.like_count}}</span>
                <span>获赞</span>
              </div>
            </div>
        </div>
        <!-- 未登录显示的头部区域 -->
        <div class="header no-login" v-else>
                 <img
                  class="mobile-img"
                  src="~@/assets/mobile.png"
                  @click="$router.push('/login')"
                >
        </div>
      </div>

      <div class="main">
        <!-- 用户主体区域 -->
        <div class="grid-nav">
       <van-grid class="nav-grid" :column-num="2" clickable >
          <van-grid-item text="收藏">
            <i slot="icon" class="toutiao toutiao-shoucang"></i>
            <span class="text" slot="text">收藏</span>
          </van-grid-item>
          <van-grid-item text="文字">
            <i slot="icon" class="toutiao toutiao-lishi"></i>
            <span class="text" slot="text">历史</span>
          </van-grid-item>
        </van-grid>
        </div>
            <van-cell title="消息通知" is-link url="" />
            <van-cell title="实名认证" is-link url="" />
            <van-cell title="用户反馈" is-link url="" />
            <van-cell title="小智同学" is-link url="" />
            <van-cell title="系统设置" is-link url="" />
            <van-cell class="logout-cell" title="退出登录" center v-if="showLogin"  @click="onLogout"/>
      </div>
    </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'MyPage',
  components: {},
  props: {},
  data () {
    return {
      // userinfo: {}
      showLogin: false
    }
  },
  computed: {
    ...mapState(['tokens', 'userinfo'])
  },
  watch: {},
  created () {
    if (this.tokens) {
      this.$store.dispatch('loadUserInfo')
      this.isLogin()
    }
  },
  mounted () {

  },
  methods: {
    isLogin () {
      this.showLogin = true
    },
    onLogout () {
      this.$dialog.confirm({ title: '确认退出吗' }).then(() => {
        this.$store.commit('removeUserToken')
        this.showLogin = false
      }).catch(err => err)
    }
  }
}
</script>

<style scoped lang="less">
.header {
    width: 750px;
    height: 401px;
    background: url("~@/assets/banner.png") no-repeat;
    background-size: cover;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    }
.mobile-img {
      width: 132px;
      height: 132px;
      vertical-align: middle;
    }
.base{
      width: 750px;
      height: 401px;
      display: flex;
      justify-content:space-between;
      align-items: center;
}
.left{
     text-align: center;
}
.data{
      width: 750px;
    height: 200px;
  display: flex;
  justify-content: space-around;
  .data-item {
    height: 130px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #fff;
    span:nth-child(1) {
      font-size: 36px;
      margin-bottom: 15px;
    }
    span:nth-child(2) {
      font-size: 23px;
    }
  }
}
.nav-grid {
  margin: 0 5px 5px 10px;
  background: #fff;
  .toutiao {
    font-size: 45px;
  }
  .toutiao-shoucang {
    color: #EB5253;
  }
  .toutiao-lishi {
    color: #FF9D1D;
  }
  .text {
    color: #000;
    margin-top: 8px;
    font-size: 28px;
  }
}
.logout-cell {
  height: 100px;
  text-align: center;
  color: #EB5253;
  margin: 10px 0;
  font-size: 30px;
}
</style>
